<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keywords" placeholder="请输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <!--表格开始-->
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="ID" width="120px" align="center">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.id }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="反馈时间" width="250px" align="center">
        <template slot-scope="scope">
          <el-tag>{{ renderTime(scope.row.createdAt) }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="用户手机" width="220px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.UserPhone.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="图片" width="220px" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.images.length <= 0" type="danger">暂无图片</el-tag>
          <span v-if="scope.row.images.length > 0">
            <img :src="scope.row.images[0]" style="width: 30px;height: 30px;" @click="image(scope.row.images)">
          </span>
        </template>
      </el-table-column>
      <el-table-column label="反馈内容">
        <template slot-scope="scope">
          <span>{{ scope.row.desc }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <el-dialog
      title="详情"
      :visible.sync="visible"
      width="40%"
      :before-close="visibleClose"
    >
      <el-carousel v-if="imgList.length">
        <el-carousel-item v-for="item in imgList" :key="item" style="text-align: center;">
          <img :src="item" style="height:100%;">
        </el-carousel-item>
      </el-carousel>
    </el-dialog>
  </div>
</template>

<script>
import waves from '@/directive/waves'
import Pagination from '@/components/Pagination'
import { feedback } from '@/api/feedback'
import { renderTime } from '../../utils'
export default {
  name: 'Lists',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
      visible: false,
      imgList: [],
      listQuery: {
        page: 1,
        limit: 10,
        keywords: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    renderTime,
    // 获取数据
    getList() {
      this.listLoading = true
      feedback(this.listQuery).then(res => {
        const { data: { count, rows }} = res.data
        this.total = count
        this.list = rows
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      }).catch(err => {
        console.log(err)
      })
    },
    // 分页
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    visibleClose() {
      this.visible = false
    },
    image(img) {
      this.imgList = img
      this.visible = true
    }
  }
}
</script>
<style></style>
